package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;

/**
 * 通知公告实体类
 *
 * @author Teaching Server
 * @since 1.0.0
 */
@Getter
@Setter
@ToString(exclude = {"noticeType", "creator", "schedule"})
@EqualsAndHashCode(of = "noticeId")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "notices", indexes = {
        @Index(name = "idx_notice_created_at", columnList = "created_at"),
        @Index(name = "idx_notice_type", columnList = "type_id")
})
public class NoticeEntity {

    /**
     * 通知ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "notice_id")
    private Long noticeId;

    /**
     * 通知标题
     */
    @NotBlank(message = "通知标题不能为空")
    @Size(max = 200, message = "通知标题长度不能超过200个字符")
    @Column(name = "title", nullable = false, length = 200)
    private String title;

    /**
     * 通知类型ID
     */
    @NotNull(message = "通知类型ID不能为空")
    @Column(name = "type_id", nullable = false)
    private Long typeId;

    /**
     * 通知描述
     */
    @Size(max = 500, message = "通知描述长度不能超过500个字符")
    @Column(name = "description")
    private String description;

    /**
     * 通知内容
     */
    @NotBlank(message = "通知内容不能为空")
    @Column(name = "content", nullable = false, columnDefinition = "TEXT")
    private String content;

    /**
     * 关联课表ID
     */
    @Column(name = "schedule_id")
    private Long scheduleId;

    /**
     * 创建人ID
     */
    @NotNull(message = "创建人ID不能为空")
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    /**
     * 创建时间
     */
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt;

    /**
     * 通知类型实体
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type_id", insertable = false, updatable = false)
    private NoticeTypeEntity noticeType;

    /**
     * 创建人实体
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "created_by", insertable = false, updatable = false)
    private UserEntity creator;

    /**
     * 关联课表实体
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "schedule_id", insertable = false, updatable = false)
    private ScheduleEntity schedule;
}
